// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	2/15/2015 4:55:44 PM				
// -----------------------------

#include "ApplicationView.h"

#include "Engine.h"
#include "..\Source\Game.h"

#include <wrl\client.h>

using namespace Platform::Runtime::InteropServices;
using namespace Windows::Foundation;

ApplicationView::ApplicationView()
{

}

void ApplicationView::SetWindow(CoreWindow^ window)
{
	// Save the Window Handle of the CoreWindow
	m_CoreWindow = window;
}

void ApplicationView::Initialize(CoreApplicationView^ applicationView)
{
	applicationView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &ApplicationView::OnActivated);

	CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &ApplicationView::OnSuspending);
	CoreApplication::Resuming += ref new EventHandler<Object^>(this, &ApplicationView::OnResuming);
	CoreApplication::Exiting += ref new EventHandler<Object ^>(this, &ApplicationView::OnExiting);
}
void ApplicationView::Uninitialize()
{

}

void ApplicationView::Load(String^ entryPoint)
{
}
void ApplicationView::Run()
{
	// Initialize the Engine Instance
	Flow::IGame* lpGame = new Game();
	if (!Flow::Engine::Initialize(lpGame))
		return;

	// Run the Engine
	Flow::Engine::Run();

	// Destroy the Engine Instance
	Flow::Engine::Uninitialize();
}

void ApplicationView::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
	// Activate the Core Window
	CoreWindow::GetForCurrentThread()->Activate();
}
void ApplicationView::OnSuspending(Object^ sender, SuspendingEventArgs^ args)
{
}
void ApplicationView::OnResuming(Object^ sender, Object^ args)
{
}

void ApplicationView::OnExiting(Object ^sender, Object ^args)
{
	Flow::Engine::Exit();
}
